using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace YATC
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class AudioLibrary : Microsoft.Xna.Framework.GameComponent
    {
        private SoundEffect menuSelect;
        private SoundEffect clearLine;
        private SoundEffect pienceCollision;
        private SoundEffect startScene;

    	private Random rando;
        
        //Songs
        private Song[] theme;
 

        private int mNb = 5;


        public AudioLibrary(Game game)
            : base(game)
        {
        	rando = new Random();
            Score.musicIndex = rando.Next(mNb);
            theme = new Song[mNb];
        }
     
        public void LoadContent(ContentManager content)
        {
            menuSelect = content.Load<SoundEffect>("Sounds\\menuSelect"); Score.percentage++;
            clearLine = content.Load<SoundEffect>("Sounds\\clearLine"); Score.percentage++;
            pienceCollision = content.Load<SoundEffect>("Sounds\\pieceCollision"); Score.percentage++;
            startScene = content.Load<SoundEffect>("Sounds\\startScene"); Score.percentage++;
            //Musik
            theme[0] = content.Load<Song>("Music\\theme0"); Score.percentage++;
            theme[1] = content.Load<Song>("Music\\theme1"); Score.percentage++;
			theme[2] = content.Load<Song>("Music\\theme2"); Score.percentage++;
			theme[3] = content.Load<Song>("Music\\theme3"); Score.percentage++;
			theme[4] = content.Load<Song>("Music\\theme4"); Score.percentage++;

        }
        

        public SoundEffect MenuSelect
        {
            get { return menuSelect;}
        }
        public SoundEffect ClearLine
        {
            get{ return clearLine;}
        }
        public  SoundEffect PieceCollision
        {
            get{ return pienceCollision;}
        }
        public SoundEffect StartScene
        {
            get{ return startScene;}
        }
        public Song GetNextMusic()
        {
            Score.musicIndex++;
            if (Score.musicIndex < mNb)
                return theme[Score.musicIndex];
            if(Score.musicIndex == mNb)
            {
                Score.musicIndex = 0;
                return theme[0];
            }
            //passiert eigentlich niemals
            return theme[0];
        }
        public Song GetPreviosMusic()
        {
            Score.musicIndex--;

            if (Score.musicIndex >= 0)
                return theme[Score.musicIndex];
            if(Score.musicIndex < 0)
            {
                Score.musicIndex = mNb-1;
                return theme[mNb-1];
            }
            //passiert auch niemals. Nur damit kein void ist.
            return theme[0];
        }
        public Song GetCurrentMusic()
        {
            return theme[Score.musicIndex];
        }


		public Song GetGreditSong()
		{
			return theme[1];
		}
	}
}